﻿@model Chess.Models.HomeModel
@{
    ViewBag.Title = "DangNhap";
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Đăng nhập</title>
    <link href="@Url.Content("~/Content/Css/DangNhap.css")" rel="stylesheet" type="text/css" />    
    <script src="../../Content/Js/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#DNUsername').addClass("TextBoxStyle");
            $('#DNMatKhau').addClass("TextBoxStyle");
            $('#DKHoTen').addClass("TextBoxStyle01");
            $('#DKNgaySinh').addClass("TextBoxStyle01");
            $('#DKUserName').addClass("TextBoxStyle01");
            $('#DKPassword').addClass("TextBoxStyle01");
            $('#DKNhapLaiMatKhau').addClass("TextBoxStyle01");
            $('#DKDiaChi').addClass("TextBoxStyle01");
            $('#DKDienThoai').addClass("TextBoxStyle01");
            $('#DKEmail').addClass("TextBoxStyle01");

        });
    </script>

    <script language="javascript" type="text/javascript">
        window.fbAsyncInit = function () {
            FB.init({
                appId: '124636791040644',
                status: true, cookie: false, xfbml: true, oauth: true
            });
        };
        function afterFacebookConnect() {

            FB.getLoginStatus(function (response) {
                if (response.authResponse) {                    
                    window.location = "../Account/FacebookLogin?token=" +
                           response.authResponse.accessToken;
                } else {                    
                    // user clicked Cancel
                }
            });
        };


        $(document).ready(function () {
            if (document.getElementById('fb-root') != undefined) {
                var e = document.createElement('script');
                e.type = 'text/javascript';
                e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
                e.async = true;
                document.getElementById('fb-root').appendChild(e);
            }

            setTimeout(function () {

                $("#KetQuaDangNhap").fadeOut("slow", function () {
                    $("#KetQuaDangNhap").remove();
                });

            }, 2000);

            setTimeout(function () {
                $("#KetQuaDangKy").fadeOut("slow", function () {
                    $("#KetQuaDangKy").remove();
                });
            }, 2000);

        });
    </script>

    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")"
     type="text/javascript"></script>
    <link href="@Url.Content("~/Content/openid-shadow.css")"
     rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/openid.css")" 
     rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/openid-en.js")" 
     type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/openid-jquery.js")" 
     type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            openid.init('openid_identifier');
        });
    </script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
</head>

<body>

    @if (ViewBag.KetQuaDangNhap != null)
    { 
        <div id="KetQuaDangNhap">Đăng nhập không thành công!</div>       
    }
    @if (ViewBag.KetQuaDangKy != null)
    { 
        <div id="KetQuaDangKy">@ViewBag.KetQuaDangKy</div>
    }	
    <div id="wrap">
        <div id="header">
            <div id="contents">
                <div id="logo">
                    <img src="@Url.Content("~/Content/Images/chess-logo--blue.png")"/>
                </div>
                <div id="loginzone">
                    <p style="color: #FFF; font-weight: bold; font-size: 14px;">Đăng nhập:</p>
                    <p style="color: #FFF; font-weight: bold; font-size: 14px;">&nbsp;</p>
                    <form id="form1" name="form1" method="post" action="">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="65%" align="right" valign="middle">
                                    <label for="DN_TenDangNhap"></label>
                                    @Html.EditorFor(model => model.DNUsername) </td>
                                <td width="35%" rowspan="2" valign="middle">
                                    <input id="ButtonDangNhap" type="image" src="@Url.Content("~/Content/Images/Dang_Nhap.png")"  /></td>
                            </tr>
                            <tr>
                                <td align="right" valign="middle">
                                    <label for="DN_MatKhau"></label>
                                    @Html.EditorFor(model => model.DNMatKhau)</td>
                            </tr>
                        </table>
                    </form>
                    <p style="color: #FFF; font-weight: bold">&nbsp;</p>
                    <p style="color: #FFF; font-weight: bold; font-size: 14px;">Facebook OAuth:</p>
                    <div style="text-align:center">
                        <fb:login-button perms="email,user_checkins" onlogin="afterFacebookConnect();"
                            autologoutlink="false"></fb:login-button>
                    </div>

                    <div id="fb-root" style="display: inline; margin-left: 20px;"></div>

                    <p style="color: #FFF; font-weight: bold; font-size: 14px;">&nbsp;</p>
                </div>
            </div>
        </div>
        <div id="container" class="clear">
            <div id="contents02">
                <div id="DangKy">
                    @using (Html.BeginForm("DangKyTaiKhoan", "Account"))
                    { 
                        <p>&nbsp;</p>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td colspan="2">
                                    <p style="font-weight: bold; font-size: 18px; color: #4979b4">ĐĂNG KÝ TÀI KHOẢN</p>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">&nbsp;</td>
                                <td>
                                    <p>&nbsp;</p>
                                    <p>&nbsp;</p>
                                    <p>&nbsp;</p>
                                </td>
                            </tr>
                            <tr>
                                <td width="31%" align="right">Họ tên: </td>
                                <td width="69%">
                                    <label for="DK_HoTen"></label>
                                    @Html.EditorFor(model => model.DKHoTen)</td>
                            </tr>
                            <tr>
                                <td align="right">Ngày sinh: </td>
                                <td>@Html.EditorFor(model => model.DKNgaySinh)</td>
                            </tr>
                            <tr>
                                <td align="right">Tên đăng nhập: </td>
                                <td>
                                    @Html.EditorFor(model => model.DKUserName)
                                    <span class="InValidUserName" style="color: red; font-weight: bold">( Tên đăng nhập đã tồn tại !)</span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">Mật khẩu: </td>
                                <td>@Html.EditorFor(model => model.DKPassword)</td>
                            </tr>
                            <tr>
                                <td align="right">Nhập lại mật khẩu: </td>
                                <td>@Html.EditorFor(model => model.DKNhapLaiMatKhau)</td>
                            </tr>
                            <tr>
                                <td align="right">Địa chỉ: </td>
                                <td>@Html.EditorFor(model => model.DKDiaChi)</td>
                            </tr>
                            <tr>
                                <td align="right">Số điện thoại: </td>
                                <td>@Html.EditorFor(model => model.DKDienThoai)</td>
                            </tr>
                            <tr>
                                <td align="right">Email: </td>
                                <td>@Html.EditorFor(model => model.DKEmail)</td>
                            </tr>
                            <tr>
                                <td align="right">&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center">
                                    <input id="ButtonDangKy" type="image" src="@Url.Content("~/Content/Images/Dang_Ky.png")" width="127" height="30" /></td>
                            </tr>
                        </table>
                        <p>&nbsp;</p>  
                    }
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                </div>

                <div id="DangNhapOpenID">
                    <p>&nbsp;</p>
                    <p style="font-weight: bold; font-size: 18px; color: #4979b4">ĐĂNG NHẬP BẰNG OPEN ID</p>
                    <form action="Account/Authenticate?ReturnUrl=@HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"])" method="post" id="openid_form">
                        <input type="hidden" name="action" value="verify" />
                        <div id="openid_btns">
                        </div>
                        <div id="openid_input_area">
                            @Html.TextBox("openid_identifier")
                            <input type="submit" value="Log On" />
                        </div>
                        
                        <div>
                            @if (Model != null)
                            {
                                if (String.IsNullOrEmpty(Model.UserName))
                                {
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.OpenID)
                                </div>
                                <div class="editor-field">
                                    @Html.DisplayFor(model => model.OpenID)
                                </div>
                                <p class="button">
                                    @Html.ActionLink("New User ,Register", "Register", new { OpenID = Model.OpenID })
                                </p>
                                }
                                else
                                {
                                    //user exist 
                                <p class="buttonGreen">
                                    <a href="@Url.Action("Index", "Home")">Welcome , @Model.UserName, Continue..." </a>
                                </p>

                                }
                            }
                        </div>
                    </form>
                </div>

                <div class="clear"></div>
            </div>

        </div>
    </div>
        <script type="text/javascript">
            $(document).ready(function () {
            
                var isValidRegister = false;
                //Khởi tạo giao diện.
                $('.InValidUserName').hide();
            
                $('#DKUserName').live('change', function () {

                    //Xử lý ajax kiểm tra tên đăng nhập hợp lệ.
                    var URL = "Account/KiemTraTaiKhoan/" + $('#DKUserName').val();
                    $.ajax({
                        type: "POST",
                        url: URL,
                        data: {},
                        dataType: "json",
                        success: function (data) {
                            if (data.IsValidUserName == true) {
                                $('.InValidUserName').hide();
                                isValidRegister = true;
                            }
                            else {
                                $('.InValidUserName').show();
                                isValidRegister = false;
                            }
                        }
                    });

                });


                setTimeout(function () {

                    $("#KetQuaDangNhap").fadeOut("slow", function () {
                        $("#KetQuaDangNhap").remove();
                    });

                }, 2000);

                setTimeout(function () {
                    $("#KetQuaDangKy").fadeOut("slow", function () {
                        $("#KetQuaDangKy").remove();
                    });
                }, 2000);
            });
        </script>         
</body>
</html>
